package nxt.WallRobo_10;


import lejos.nxt.*;
public class Correctionthread extends Thread
{
	public static Object wait_for_correction = new Object();
	int Correction = 0;
	public Usthread ust;
	public Correctionthread(){}

	public void run()
	{
		
		
		Motor.A.stop();
		Motor.B.stop();
		//Correction = ((-Drift/360) * Umfang wendekreis*360)/Radumfang
		Correction = (int) Math.round(-Usthread.Drift*2.399977);
		Motor.A.setSpeed(150);		
		Motor.B.setSpeed(150);	
		if(Correction>=0)
		{
			Motor.B.rotate(-Math.abs(Correction));
		}
		else
		{
			Motor.A.rotate(-Math.abs(Correction));
		}
		Motor.A.setSpeed(300);		
		Motor.B.setSpeed(300);

		LCD.clear();
		LCD.drawInt(Correction, 0, 4);

		
		Usthread.Drift=0;
		Sound.playTone(400, 500);
		Usthread.last_distance_distance = 0;
		Usthread.last_distance_Tacho = 0;
		Usthread.current_distance_distance = 0;
		Usthread.current_distance_Tacho = 0;
		Usthread.correction_is_needed = false;
		try
		{
			synchronized(wait_for_correction)
			{	
				wait_for_correction.notifyAll();
			}
		}
		catch (Exception e){}
	}
	
}
